<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form :inline="true" left :model="formInline" label-width="140px" class="demo-form-inline">
        <el-form-item :label='$t("会员到期提醒")'>

          <el-radio-group v-model="formInline.isNotify">
            <el-radio :label="0">{{ $t('否') }}</el-radio>
            <el-radio :label="1">
              {{ $t('是') }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <div></div>
        <el-form-item :label='$t("会员到期提醒天数")'>
          <el-input v-model="formInline.advanceDay" style="width:500px" :placeholder='$t("请填写会员到期提醒天数")'></el-input>
        </el-form-item>
        <div></div>
        <el-form-item :label='$t("提醒内容")'>
          <el-input type="textarea" rows='10' style="width:500px;" v-model="formInline.content"></el-input>
        </el-form-item>
        <div></div>
        <el-form-item :label='$t("提醒方式")'>
          <el-checkbox-group v-model="formInline.types">
            <el-checkbox v-for="city in checkType" :label="city.id" :key="city.id">{{ city.text }}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <div></div>
        <el-form-item style='margin-left:290px'>
          <el-button type="info" plain1 icon="el-icon-success" @click="handleFilter">{{ $t('保存') }}</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>

import { payMemberNotify, levelpayMemberNotify } from '@/api/user'
import { getLevelMemberNotify, getPayMemberNotify } from '../../../api/user'

export default {
  name: 'SystemMessage',
  data() {
    return {
      formInline: {
        isNotify: true,
        advanceDay: '',
        content: '',
        types: []
      },
      checkAll: false,
      checkType: [{ id: 1, text: this.$t('系统消息') }, { id: 2, text: this.$t('短信') }, { id: 3, text: this.$t('邮件') }],
      checkTypes: [],
      checkedCities: ['系统消息', '短信'],

      cities: ['系统消息', '短信', '邮件'],
      isIndeterminate: true,
      isChecked: false,
    }
  },
  mounted() {
    if (this.$route.name == 'PaidMessage') {
      this.type = 2

      getPayMemberNotify().then(response => {
        this.formInline = _.assign(this.formInline, response.data.data)
        if (this.formInline.isNotify == 1) {
          this.isChecked = true;
        }
      })
    } else {
      getLevelMemberNotify().then(response => {
        this.formInline = _.assign(this.formInline, response.data.data)

        if (this.formInline.isNotify == 1) {
          this.isChecked = true;
        }
      })
    }
  },
  methods: {



    handleFilter() {
      if (!this.formInline.advanceDay) {
        this.$message.error('请填写会员到期提醒天数')
        return
      } else if (!this.formInline.content) {
        this.$message.error('请填写提醒内容')
        return
      } else if (this.formInline.types.length <= 0) {
        this.$message.error('请选择提醒方式')
        return
      }
      this.formInline.isNotify = this.formInline.isNotify == true ? 1 : 0
      if (this.type == 2) {
        payMemberNotify(this.formInline).then(response => {
          this.$message({
            type: 'success',
            message: response.data.data
          })
        }).catch(() => {
          this.$message({
            type: 'success',
            message: this.$t('失败!')
          })
        })
      } else {
        levelpayMemberNotify(this.formInline).then(response => {
          this.$message({
            type: 'success',
            message: response.data.data
          })
        }).catch(() => {
          this.$message({
            type: 'success',
            message: this.$t('失败!')
          })
        })
      }

    }
  }
}
</script>

<style scoped>
/*.el-form-item__label{*/
/*  text-align: left;*/
/*}*/
/*.daytime{*/
/*  color: #606266; font-size: 14px; font-weight: 700;*/
/*}*/
</style>
